#include<iostream>
#include<string>
#include<fstream>
#include <list>
using namespace std;
class Subject;
class Observer {
public:
    virtual void update(Subject* subject) = 0;
};

class Subject {
public:
    void attach(Observer* obs) {
        _observers.push_back(obs);
    }
    void detach(Observer* obs) {
        _observers.remove(obs);
    }
    void Notify() {
        for (Observer* obs : _observers)
            obs->update(this);
    }
    virtual string getState() = 0;
    virtual void setState(string s) = 0;

protected:
    list<Observer*> _observers;
};

class Student   //学生
{
public:
    string id;
    string name;
    void set(string _name, string _id)
    {
        name = _name;
        id = _id;
    }

    void print()
    {
        cout << "姓名：" << name << endl;
        cout << "学号：" << id << endl;
    }

    void save()
    {
        ofstream fout("student.txt");
        fout << "姓名：" << name << endl;
        fout << "学号：" << id << endl;
        fout.close();
    }
};

class Luntai
{
public:
    string xinghao;
    string chicun;

    void set(string _xinghao, string _chicun)
    {
        xinghao = _xinghao;
        chicun = _chicun;
    }

    void print()
    {
        cout << "底盘轮胎型号：" << xinghao << endl;
        cout << "底盘轮胎尺寸：" << chicun << endl;
    }

    void save()
    {
        ofstream fout("luntai.txt");
        fout << "底盘轮胎型号：" << xinghao << endl;
        fout << "底盘轮胎尺寸：" << chicun << endl;
        fout.close();
    }
};

class Chassis:public Observer  //底盘
{
public:
    void update(Subject* subject) {
        teacherPhoneNumber = subject->getState();
        if(teacherPhoneNumber=="1")
        cout << "后退" << endl;
        if (teacherPhoneNumber == "2")
            cout << "左转" << endl;
        if (teacherPhoneNumber == "3")
            cout << "右转" << endl;
    }
private:
    string teacherPhoneNumber;
public:
    string id;
    string xinghao;
    string zhouju;
    string lunju;
    string jianxi;
    string banjing;
    string qudongxingshi;
    string xingcheng;
    Luntai luntai;
    void set(string _id, string _xinghao, string _zhouju, string _lunju, string _jianxi, string _banjing, string _qudongxingshi, string _xingcheng)
    {
        id = _id;
        xinghao = _xinghao;
        zhouju = _zhouju;
        lunju = _lunju;
        jianxi = _jianxi;
        banjing = _banjing;
        qudongxingshi = _qudongxingshi;
        xingcheng = _xingcheng;
    }
    void print()
    {
        cout << "底盘编号：" << id << endl;
        cout << "底盘型号：" << xinghao << endl;
        cout << "底盘轴距：" << zhouju;
        cout << "底盘轮距：" << lunju;
        cout << "底盘最小离地间隙：" << jianxi << endl;
        cout << "底盘最小转动半径：" << banjing << endl;
        cout << "底盘驱动形式：" << qudongxingshi << endl;
        cout << "底盘最大行程：" << xingcheng << endl;
        luntai.print();
    }
    void save()
    {
        ofstream fout("Chassis.txt");
        fout << "底盘编号：" << id << endl;
        fout << "底盘型号：" << xinghao << endl;
        fout << "底盘轴距：" << zhouju << endl;
        fout << "底盘轮距：" << lunju << endl;
        fout << "底盘最小离地间隙：" << jianxi << endl;
        fout << "底盘最小转动半径：" << banjing << endl;
        fout << "底盘驱动形式：" << qudongxingshi << endl;
        fout << "底盘最大行程：" << xingcheng << endl;
        fout << "底盘轮胎型号：" << luntai.xinghao << endl;
        fout << "底盘轮胎尺寸：" << luntai.chicun << endl;
        fout.close();
    }
};




class AGXSuite   //AGX套件
{
public:
    string xinghao;
    string AI;
    string CUDA;
    string TensorCore;
    string xiancun;
    string cunchu;
    void set(string _xinghao, string _AI, string _CUDA, string _TensorCore, string _xiancun, string _cunchu)
    {
        xinghao = _xinghao;
        AI = _AI;
        CUDA = _CUDA;
        TensorCore = _TensorCore;
        xiancun = _xiancun;
        cunchu = _cunchu;
    }
    void print()
    {
        cout << "AGX型号：" << xinghao << endl;
        cout << "AGX AI：" << AI << endl;
        cout << "AGX CUDA：" << CUDA << endl;
        cout << "AGX TensorCore：" << TensorCore << endl;
        cout << "AGX显存：" << xiancun << endl;
        cout << "AGX存储：" << cunchu << endl;
    }
    void save()
    {
        ofstream fout("AGXSuite.txt");
        cout << "AGX型号：" << xinghao << endl;
        cout << "AGX AI" << AI << endl;
        cout << "AGX CUDA：" << CUDA << endl;
        cout << "AGX TensorCore：" << TensorCore << endl;
        cout << "AGX显存：" << xiancun << endl;
        cout << "AGX存储：" << cunchu << endl;
        fout.close();
    }
};

class Bin_camera  //双目摄像头
{
public:
    string xinghao;
    string shexiangtou;
    string fenbianlv;
    string zhenlv;
    string FOV;
    string shenduzhenlv;
    void set(string _xinghao, string _shexiangtou, string _fenbianlv, string _zhenlv, string _FOV, string _shenduzhenlv)
    {
        xinghao = _xinghao;
        shexiangtou = _shexiangtou;
        fenbianlv = _fenbianlv;
        zhenlv = _zhenlv;
        FOV = _FOV;
        shenduzhenlv = _shenduzhenlv;
    }
    void print()
    {
        cout << "摄像头型号" << xinghao << endl;
        cout << "摄像头：" << shexiangtou << endl;
        cout << "摄像头RGB分辨帧率：" << fenbianlv << endl;
        cout << "摄像头帧率：" << zhenlv << endl;
        cout << "摄像头FOV：" << FOV;
        cout << "摄像头深度帧率：" << shenduzhenlv << endl;
    }
    void save()
    {
        ofstream fout("Bin_camera.txt");
        cout << "摄像头型号" << xinghao << endl;
        cout << "摄像头：" << shexiangtou << endl;
        cout << "摄像头RGB分辨帧率：" << fenbianlv << endl;
        cout << "摄像头RGB帧率：" << zhenlv << endl;
        cout << "摄像头FOV：" << FOV << endl;
        cout << "摄像头深度帧率：" << shenduzhenlv << endl;
        fout.close();
    }
};

class Lidar:public Subject
{
public:
    string getState() {
        return _phoneNumber;
    }
    void setState(string s) {
        _phoneNumber = s;
    }
private:
    string _phoneNumber;
public:
    string xinghao;
    string tongdaoshu;
    string ceshifanwei;
    string gonghao;
    void set(string _xinghao, string _tongdaoshu, string _ceshifanwei, string _gonghao)
    {
        xinghao = _xinghao;
        tongdaoshu = _tongdaoshu;
        ceshifanwei = _ceshifanwei;
        gonghao = _gonghao;
    }
    void print()
    {
        cout << "激光雷达型号：" << xinghao << endl;
        cout << "激光雷达通道数：" << tongdaoshu << endl;
        cout << "激光雷达测试范围：" << ceshifanwei << endl;
        cout << "激光雷达功耗：" << gonghao << endl;
    }
    void save()
    {
        ofstream fout("Lidar.txt");
        fout << "激光雷达型号：" << xinghao << endl;
        fout << "激光雷达通道数：" << tongdaoshu << endl;
        fout << "激光雷达测试范围：" << ceshifanwei << endl;
        fout << "激光雷达功耗：" << gonghao << endl;
        fout.close();
    }

};

class Gyroscope
{
public:
    string xinghao;
    string changjia;
    void set(string _xinghao, string _changjia)
    {
        xinghao = _xinghao;
        changjia = _changjia;
    }
    void print()
    {
        cout << "陀螺仪型号：" << xinghao << endl;
        cout << "陀螺仪厂家：" << changjia << endl;
    }
    void save()
    {
        ofstream fout("Gyroscope.txt");
        fout << "陀螺仪型号：" << xinghao << endl;
        fout << "陀螺仪厂家：" << changjia << endl;
        fout.close();
    }
};

class Screen
{
public:
    string chicun;
    string xinghao;
    void set(string _chicun, string _xinghao)
    {
        chicun = _chicun;
        xinghao = _xinghao;
    }
    void print()
    {
        cout << "显示屏尺寸：" << chicun << endl;
        cout << "显示屏型号：" << xinghao << endl;
    }
    void save()
    {
        ofstream fout("Screen.txt");
        fout << "显示屏尺寸：" << chicun << endl;
        fout << "显示屏型号：" << xinghao << endl;
        fout.close();
    }
};

class Battery
{
public:
    string canshu;
    string duiwaigongdian;
    string chongdianshichang;
    void set(string _canshu, string _duiwaigongdian, string _chongdianshichang)
    {
        canshu = _canshu;
        duiwaigongdian = _duiwaigongdian;
        chongdianshichang = _chongdianshichang;
    }
    void print()
    {
        cout << "电池参数：" << canshu << endl;
        cout << "电池对外供电：" << duiwaigongdian << endl;
        cout << "电池充电时长：" << chongdianshichang << endl;
    }
    void save()
    {
        ofstream fout("Battery.txt");
        fout << "电池参数：" << canshu << endl;
        fout << "电池对外供电：" << duiwaigongdian << endl;
        fout << "电池充电时长：" << chongdianshichang << endl;
        fout.close();
    }
};

class Car
{
public:
    string id;
    Chassis chassis;    //底盘
    AGXSuite agxsuite;  //agx套件
    Bin_camera bin_camera;//双目摄像头
    Lidar lidar;    //激光雷达
    Gyroscope gyroscope;//陀螺仪
    Screen screen;  //显示屏
    Battery battery;  //电池
    Student student;
    void setID(string _id)
    {
        id = _id;
    }
    void print()
    {
        student.print();
        cout << "小车编号：" << id << endl;
        chassis.print();
        agxsuite.print();
        bin_camera.print();
        lidar.print();
        gyroscope.print();
        screen.print();
        battery.print();
    }
    void save()
    {
        ofstream fout("car.txt");
        fout << "学号：" << student.id << "\n姓名: " << student.name << "\n小车编号：" << id << "\n底盘编号：" << chassis.id << "\n底盘型号：" << chassis.xinghao << "\n底盘轴距：" << chassis.zhouju << "   底盘轮距：" << chassis.lunju << "   底盘最小离地间隙：" << chassis.jianxi << "\n底盘最小转弯半径：" << chassis.banjing << "\n底盘驱动形式：" << chassis.qudongxingshi << "\n底盘最大行程：" << chassis.xingcheng << "\n底盘轮胎型号：" << chassis.luntai.xinghao << "\n底盘轮胎尺寸：" << chassis.luntai.chicun << "\nAGX型号: " << agxsuite.xinghao << "\nAGX AI: " << agxsuite.AI << "\nAGX CUDA: " << agxsuite.CUDA << "\nAGX TensorCORE: " << agxsuite.TensorCore << "\nAGX显存: " << agxsuite.xiancun << "\nAGX存储: " << agxsuite.cunchu << "\n摄像头型号: " << bin_camera.xinghao << "\n摄像头: " << bin_camera.shexiangtou << "\n摄像头RGB分辨帧率: " << bin_camera.fenbianlv << "\n摄像头帧率: " << bin_camera.zhenlv << "\n摄像头FOV: " << bin_camera.FOV << "摄像头深度帧率: " << bin_camera.shenduzhenlv << "\n激光雷达型号: " << lidar.xinghao << "\n激光雷达通道数: " << lidar.tongdaoshu << "\n激光雷达测试范围: " << lidar.ceshifanwei << "\n激光雷达功耗: " << lidar.gonghao << "\n陀螺仪型号: " << gyroscope.xinghao << "\n陀螺仪厂家: " << gyroscope.changjia << "\n显示屏尺寸: " << screen.chicun << "\n显示屏型号: " << screen.xinghao << "\n电池参数: " << battery.canshu << "\n电池对外供电: " << battery.duiwaigongdian << "\n电池充电时长: " << battery.chongdianshichang << endl;
        fout.close();
    }
};

void save_student();
void read_Carxinxi(Car car[]);
void match_CarStu(Car car[]);
void show_Cardata(Car car[]);
void save_Cardata(Car car[]);
void show_menu();

int main()
{
    Car car[10];
    string select;
    read_Carxinxi(car);
    show_menu();
    while (1)
    {
        cin >> select;
        if (select == "1")
        {
            save_student();
            show_menu();
        }
        else if (select == "2")
        {
            match_CarStu(car);
            show_menu();
        }
        else if (select == "3")
        {
            show_Cardata(car);
            show_menu();
        }
        else if (select == "4")
        {
            save_Cardata(car);
            show_menu();
        }
        else if (select == "6")
        {
            cout << "欢迎下次使用！" << endl;
            break;
        }
        else if (select == "5")
        {
            cout << "请更新障碍物状态：输入1为前方，2为右前方，3为左前方" << endl;
            string n;
            cin >> n;
            Lidar t;
            Chassis s1;
            t.attach(&s1);
            t.setState(n);
            t.Notify();
            show_menu();

        }
        else
            cout << "请输入正确信息！" << endl;
    }
}

void save_student()
{
    int i = 1;
    ofstream fout("student.txt");
    while (i <= 10)
    {
        string name, id;
        cout << "请输入学生姓名：" << endl;
        cin >> name;
        cout << "请输入学生学号：" << endl;
        cin >> id;
        Student s = { name,id };
        fout << s.id << " " << s.name << endl;
        i++;
    }
    fout.close();
}

void read_Carxinxi(Car car[])
{
    ifstream fin("chexinxi.txt");
    for (int i = 0; i < 10; i++)
    {
        fin >> car[i].id >> car[i].chassis.id >> car[i].chassis.xinghao >> car[i].chassis.zhouju >> car[i].chassis.lunju >> car[i].chassis.jianxi >> car[i].chassis.banjing >> car[i].chassis.qudongxingshi >> car[i].chassis.xingcheng >> car[i].chassis.luntai.xinghao >> car[i].chassis.luntai.chicun >> car[i].agxsuite.xinghao >> car[i].agxsuite.AI >> car[i].agxsuite.CUDA >> car[i].agxsuite.TensorCore >> car[i].agxsuite.xiancun >> car[i].agxsuite.cunchu >> car[i].bin_camera.xinghao >> car[i].bin_camera.shexiangtou >> car[i].bin_camera.fenbianlv >> car[i].bin_camera.zhenlv >> car[i].bin_camera.FOV >> car[i].bin_camera.shenduzhenlv >> car[i].lidar.xinghao >> car[i].lidar.tongdaoshu >> car[i].lidar.ceshifanwei >> car[i].lidar.gonghao >> car[i].gyroscope.xinghao >> car[i].gyroscope.changjia >> car[i].screen.chicun >> car[i].screen.xinghao >> car[i].battery.canshu >> car[i].battery.duiwaigongdian >> car[i].battery.chongdianshichang;
    }
    fin.close();
}

void match_CarStu(Car car[])
{
    ifstream fin("student.txt");
    for (int i = 0; i < 10; i++)
    {
        fin >> car[i].student.name >> car[i].student.id;
    }
    fin.close();
}

void show_Cardata(Car car[])
{
    int i = 0;
    car[i].print();
    cout << "按'n'显示下一辆，按'p'显示上一辆，按'e'退出" << endl;
    while (1)
    {
        char c;
        cin >> c;
        if (c == 'n')
        {
            if (i == 9)
            {
                cout << "输入无效" << endl;
                cout << "按'n'显示下一辆，按'p'显示上一辆，按'e'退出" << endl;
            }
            else
            {
                i++;
                car[i].print();
                cout << "按'n'显示下一辆，按'p'显示上一辆，按'e'退出" << endl;
            }
        }
        else if (c == 'p')
        {
            if (i == 0)
            {
                cout << "输入无效" << endl;
                cout << "按'n'显示下一辆，按'p'显示上一辆，按'e'退出" << endl;
            }
            else
            {
                i--;
                car[i].print();
                cout << "按'n'显示下一辆，按'p'显示上一辆，按'e'退出" << endl;
            }
        }
        else if (c == 'e')
        {
            break;
        }
        else
        {
            cout << "请输入正确选项！”" << endl;
        }
    }
}

void save_Cardata(Car car[])
{
    ofstream fout("car.txt");
    for (int i = 0; i < 10; i++)
    {
        fout << "学号：" << car[i].student.id << "\n姓名: " << car[i].student.name << "\n小车编号：" << car[i].id << "\n底盘编号：" << car[i].chassis.id << "\n底盘型号：" << car[i].chassis.xinghao << "\n底盘轴距：" << car[i].chassis.zhouju << "   底盘轮距：" << car[i].chassis.lunju << "   底盘最小离地间隙：" << car[i].chassis.jianxi << "\n底盘最小转弯半径：" << car[i].chassis.banjing << "\n底盘驱动形式：" << car[i].chassis.qudongxingshi << "\n底盘最大行程：" << car[i].chassis.xingcheng << "\n底盘轮胎型号：" << car[i].chassis.luntai.xinghao << "\n底盘轮胎尺寸：" << car[i].chassis.luntai.chicun << "\nAGX型号: " << car[i].agxsuite.xinghao << "\nAGX AI: " << car[i].agxsuite.AI << "\nAGX CUDA: " << car[i].agxsuite.CUDA << "\nAGX TensorCORE: " << car[i].agxsuite.TensorCore << "\nAGX显存: " << car[i].agxsuite.xiancun << "\nAGX存储: " << car[i].agxsuite.cunchu << "\n摄像头型号: " << car[i].bin_camera.xinghao << "\n摄像头: " << car[i].bin_camera.shexiangtou << "\n摄像头RGB分辨帧率: " << car[i].bin_camera.fenbianlv << "\n摄像头帧率: " << car[i].bin_camera.zhenlv << "\n摄像头FOV: " << car[i].bin_camera.FOV << "摄像头深度帧率: " << car[i].bin_camera.shenduzhenlv << "\n激光雷达型号: " << car[i].lidar.xinghao << "\n激光雷达通道数: " << car[i].lidar.tongdaoshu << "\n激光雷达测试范围: " << car[i].lidar.ceshifanwei << "\n激光雷达功耗: " << car[i].lidar.gonghao << "\n陀螺仪型号: " << car[i].gyroscope.xinghao << "\n陀螺仪厂家: " << car[i].gyroscope.changjia << "\n显示屏尺寸: " << car[i].screen.chicun << "\n显示屏型号: " << car[i].screen.xinghao << "\n电池参数: " << car[i].battery.canshu << "\n电池对外供电: " << car[i].battery.duiwaigongdian << "\n电池充电时长: " << car[i].battery.chongdianshichang << endl;
        fout << endl << endl;
    }
    fout.close();
}

void show_menu()
{
    cout << "\t1.依次输入学生信息" << endl;
    cout << "\t2.把小车分配给学生" << endl;
    cout << "\t3.信息输出" << endl;
    cout << "\t4.信息保存" << endl;
    cout << "\t5.更新障碍物状态" << endl;
    cout << "\t6.退出" << endl;
}
//111